package com.frinder.seata.data.domain.web;

import com.frinder.seata.data.base.Result;
import com.frinder.seata.data.base.PageWrapper;
import com.frinder.seata.data.base.ModelWrapper;
import com.frinder.seata.data.domain.model.Storage;
import com.frinder.seata.data.domain.service.IStorageService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2020/08/18.
*/
@RestController
@RequestMapping("/storage")
public class StorageController {
    @Resource
    private IStorageService storageService;

    @ApiOperation(value = "添加 Storage")
    @PostMapping("/add")
    public Result add(@RequestBody Storage storage) {
        storageService.save(storage);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 删除 Storage")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        storageService.deleteById(id);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 ids 批量删除 Storage")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        storageService.deleteByIds(ids);
        return Result.defSuccess();
    }

    @ApiOperation(value = "更新 Storage")
    @PostMapping("/update")
    public Result update(@RequestBody Storage storage) {
        storageService.update(storage);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 查询 Storage")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        Storage storage = storageService.findById(id);
        return Result.dataSuccess(storage);
    }

    @ApiOperation(value = "按条件查询 Storage")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<Storage> wrapper) {
        List<Storage> list = storageService.findByModelWrapper(wrapper);
        return Result.dataSuccess(list);
    }

    @ApiOperation(value = "按条件分页查询 Storage")
    @PostMapping("/page")
    public Result page(@RequestBody PageWrapper<Storage> page) {
        PageInfo pageInfo = storageService.page(page);
        return Result.dataSuccess(pageInfo);
    }
}
